import router from "./router";
//@ts-ignore
import Nprogress from 'nprogress';
import useUserStore from '@/store/module/user';
import pinia from '@/store'
let userStore = useUserStore(pinia);
import "nprogress/nprogress.css"
//进度条的加载小圆球不要
Nprogress.configure({ showSpinner: false });
//存储用户未登录可以访问路由得路径
let whiteList = ["/home", '/hospital/register', '/hospital/detail', '/hospital/notice', '/hospital/close', '/hospital/search'];

router.beforeEach((to, from, next) => {
    Nprogress.start();
    document.title = `尚医通-${to.meta.title}`;
    let token = userStore.userInfo.token;
    if (token) {
        next();
    } else {
        if (whiteList.includes(to.path)) {
            next();
        } else {
            userStore.dialogVisible = true;
            next({ path: '/home', query: { redirect: to.fullPath } })
        }

    }

});

router.afterEach((to, from) => {
    Nprogress.done();
})